const ueSdkModule = require('../modules/ueSdk');

async function ueSdkRoutes(fastify) {
  // 创建SDK文档
  fastify.post('/ue-sdk/create', async (request, reply) => {
    try {
      const result = await ueSdkModule.createSdk(request.body);
      reply.send(result);
    } catch (error) {
      reply.code(400).send({
        code: 400,
        status: 'error',
        message: error.message
      });
    }
  });

  // 更新SDK文档
  fastify.post('/ue-sdk/update', async (request, reply) => {
    try {
      const result = await ueSdkModule.updateSdk(request.body);
      reply.send(result);
    } catch (error) {
      reply.code(400).send({
        code: 400,
        status: 'error',
        message: error.message
      });
    }
  });

  // 删除SDK文档
  fastify.post('/ue-sdk/delete', async (request, reply) => {
    try {
      const result = await ueSdkModule.deleteSdk(request.body);
      reply.send(result);
    } catch (error) {
      reply.code(400).send({
        code: 400,
        status: 'error',
        message: error.message
      });
    }
  });

  // 获取SDK文档详情
  fastify.get('/ue-sdk/detail', async (request, reply) => {
    try {
      const result = await ueSdkModule.getSdkDetail(request.query);
      reply.send(result);
    } catch (error) {
      reply.code(400).send({
        code: 400,
        status: 'error',
        message: error.message
      });
    }
  });

  // 获取SDK文档列表（按大类分组）
  fastify.get('/ue-sdk/list', async (request, reply) => {
    try {
      const result = await ueSdkModule.getSdkList();
      reply.send(result);
    } catch (error) {
      reply.code(400).send({
        code: 400,
        status: 'error',
        message: error.message
      });
    }
  });

  // 搜索SDK文档
  fastify.get('/ue-sdk/search', async (request, reply) => {
    try {
      const result = await ueSdkModule.searchSdk(request.query);
      reply.send(result);
    } catch (error) {
      reply.code(400).send({
        code: 400,
        status: 'error',
        message: error.message
      });
    }
  });
}

module.exports = ueSdkRoutes;